<!--
* @author luguoxiang
* @date 2021-09-07
* 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
-->
<template>
  <img :src="getFileAccessUrl(src, props.level)" v-bind="$attrs" @error="onerror" />
</template>

<script lang="ts">
export default {
  name: 'Image',
};
</script>
<script lang="ts" setup>
import { watchEffect, ref } from 'vue';
import { getFileAccessUrl, ThumbnailSizeEnum } from '@/soar';

interface Props {
  src: string;
  defaultSrc?: string;
  level?: ThumbnailSizeEnum;
}
const props = defineProps<Props>();

const src = ref();
watchEffect(() => {
  src.value = props.src;
});
function onerror() {
  if (src.value !== props.defaultSrc) {
    src.value = props.defaultSrc;
  }
}
</script>
